package com.fx.service.impl;

import cn.hutool.core.date.DateUtil;
import com.fx.entity.ChangeRecord;
import com.fx.mapper.ChangeRecordMapper;
import com.fx.service.ChangeRecordService;
import com.fx.util.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;


@Service
public class ChangeRecordServiceImpl implements ChangeRecordService {
    @Autowired
    private ChangeRecordMapper changeRecordMapper;
    @Autowired
    private IdWorker idWorker;

    @Override
    public ChangeRecord getById(String flId) {
        return changeRecordMapper.getById(flId);
    }

    @Override
    public List<ChangeRecord> getList(Map<String, Object> map) {
        return changeRecordMapper.queryList(map);
    }

    @Override
    public int getCount(Map<String, Object> map) {
        return changeRecordMapper.queryCount(map);
    }

    @Override
    public int save(ChangeRecord changeRecord) {
        changeRecord.setFlId(String.valueOf(idWorker.nextId()));
        changeRecord.setFlCreatedTime(DateUtil.now());
        return changeRecordMapper.save(changeRecord);
    }

    @Override
    public int updateById(ChangeRecord changeRecord) {
        return changeRecordMapper.updateById(changeRecord);
    }

    @Override
    public int remove(String flId) {
        return changeRecordMapper.remove(flId);
    }

    @Override
    public int batchRemove(String[] flIds) {
        return changeRecordMapper.batchRemove(flIds);
    }

    @Override
    public List<ChangeRecord> getListByUserId(String userId) {
        return changeRecordMapper.queryListByUserId(userId);
    }

    @Override
    public BigDecimal getWithdrawAmount(String userId) {
        return changeRecordMapper.queryTotalWithdrawAmountByUserId(userId);
    }

    @Override
    public List<ChangeRecord> getWithdrawRecodeByUserId(String userId) {
        return changeRecordMapper.queryChangeRecordByUserId(userId);
    }

}
